package org.aaron.demos;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class WifiActivity extends Activity {

	private Button open_wifi_btn, close_wifi_btn;
	private WifiManager wifiManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.wifilayout);
		initActivity();
	}

	private void initActivity() {
		open_wifi_btn = (Button) this.findViewById(R.id.open_wifi_btn);
		open_wifi_btn.setOnClickListener(new WifiOpenClickListener());
		close_wifi_btn = (Button) this.findViewById(R.id.close_wifi_btn);
		close_wifi_btn.setOnClickListener(new WifiCloseClickListener());
	}

	class WifiOpenClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Log.d("WifiActivity", "WifiOpenClickListener");
			wifiManager = (WifiManager) WifiActivity.this.getSystemService(Context.WIFI_SERVICE);
			wifiManager.setWifiEnabled(true);
			Log.d("WiFi State", wifiManager.getWifiState() + "");
		}
	}

	class WifiCloseClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			Log.d("WifiActivity", "WifiCloseClickListener");
			wifiManager.setWifiEnabled(false);
			Log.d("WiFi State", wifiManager.getWifiState() + "");
		}
	}
}
